// pages/owner/owner.js
const host = require('../../config.js').host;
const network = require('../../utils/network.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: host,
    ownerId: "",
    customerRelationId: "",
    type: 0,
    info: {
goodsList:[
  {deduction:0.01
  ,expiryDate:'2021-01-18 12:35:21'
  },
  {deduction:8888.088},
  {deduction:0.01},
]

    }
  },

  toCouponDetail(e){
    wx.navigateTo({
      url: '/pages/getcoupon/getcoupon?id=' + e.currentTarget.dataset.id
    })
  },

  changeRelationStatus() {
    let that = this;
    let type = this.data.type;
    wx.showModal({
      title: '提示',
      content: type ==0 ?'确定同意绑定吗？':'确定要解除绑定吗？',
      success: res=>{
        if(res.confirm){
          network.requestPost("/xcx/customer-relation/changeRelationStatus", {
            'id': that.data.customerRelationId,
            'type': type
          }, res => {
            // 修改成功
            if ('200' == res.data.code) {
              wx.showModal({
                title: '提示',
                content: type ==0 ?'成功绑定':'成功解除绑定',
                showCancel: false,
                confirmText: '返回',
                success: res=>{
                  if(res.confirm){
                    wx.navigateBack({
                      delta: 2,
                    })
                  }
                }
              })
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
            }
          })
        }
      }
    })
  },

  /**
   * 获取业主详情
   */
  getOwnerDetail() {

    network.requestGet('/xcx/customer/getOwnerDetail', {
      // "ownerId": this.data.ownerId
      "ownerId": 5
    }, res => {
    }, res => {
      console.log("res", res)
      if (res.data.code == '200') {
        let addressList = res.data.data.addressList;
        wx.setStorageSync('ownerPhone', res.data.data.ownerPhone);
        if(addressList.length > 0){
          wx.setStorageSync('ownerAddressName', addressList[0].name + "(" + res.data.data.ownerName + ")");
        }
        this.setData({
          info: res.data.data
        })
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      ownerId: options.ownerId,
      customerRelationId: options.customerRelationId,
      type: options.type
    })
    this.getOwnerDetail();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})